package com.crcc.common.constant;

import java.util.*;

/**
 * 数据库对应的状态码常量类
 */
public class CommonDataBaseConst {

    /**
     * 通用所有基础数据表的数据状态
     */
    public enum DATA_STATUS {
        DELETED(0, "删除"),
        NORMAL(1, "正常"),
        FROZEN(2, "停用");
        private final int code;
        private final String mess;

        DATA_STATUS(int code, String mess) {
            this.code = code;
            this.mess = mess;
        }

        public int getCode() {
            return code;
        }

        public String getMess() {
            return mess;
        }

        public static LinkedHashMap<Integer, String> getMap() {
            LinkedHashMap<Integer, String> map = new LinkedHashMap<>();
            for (DATA_STATUS as : values()) {
                map.put(as.getCode(), as.getMess());
            }
            return map;
        }
    }

    /**
     * 通用所有数据表中 是、否的数据状态
     */
    public enum YES_OR_NO {
        YES(1, "是"),
        NO(0, "否");
        private final int code;
        private final String mess;

        YES_OR_NO(int code, String mess) {
            this.code = code;
            this.mess = mess;
        }

        public int getCode() {
            return code;
        }

        public String getMess() {
            return mess;
        }

        public static LinkedHashMap<Integer, String> getMap() {
            LinkedHashMap<Integer, String> map = new LinkedHashMap<>();
            for (YES_OR_NO as : values()) {
                map.put(as.getCode(), as.getMess());
            }
            return map;
        }
    }

    /**
     * 通用所有数据表中 是、否的数据状态
     */
    public enum SEX {
        YES(1, "女"),
        NO(0, "男");
        private final int code;
        private final String mess;

        SEX(int code, String mess) {
            this.code = code;
            this.mess = mess;
        }

        public int getCode() {
            return code;
        }

        public String getMess() {
            return mess;
        }

        public static LinkedHashMap<Integer, String> getMap() {
            LinkedHashMap<Integer, String> map = new LinkedHashMap<>();
            for (SEX as : values()) {
                map.put(as.getCode(), as.getMess());
            }
            return map;
        }

        public static SEX getSex(Integer code)throws IllegalArgumentException{
            return Arrays.stream(SEX.values()).filter(s -> s.code == code).findFirst().orElse(NO);
        }
    }

}
